package com.dhcc.cdc.busi.controller;


import com.baomidou.mybatisplus.plugins.Page;
import com.dhcc.cdc.busi.entity.CdcSignEntity;
import com.dhcc.cdc.busi.service.ICdcSignService;
import com.dhcc.core.framework.annotion.BussinessLog;
import com.dhcc.core.framework.annotion.Permission;
import com.dhcc.core.framework.base.controller.BaseController;
import com.dhcc.core.framework.base.warpper.EmptyWarpper;
import com.dhcc.core.framework.exception.BizException;
import com.dhcc.core.framework.exception.BizExceptionEnum;
import com.dhcc.core.framework.result.R;
import com.dhcc.core.framework.result.page.PageFactory;
import com.dhcc.core.framework.util.CommonUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;


/**
 * 生命体征
 * 
 * @ClassName: CdcSignController
 * @Description: TODO
 * @author jumper
 * @date 2021-03-15 10:20:07
 */
@Controller
@RequestMapping("${sys.backendPath}/cdc/cdcsign")
public class CdcSignController extends BaseController {

	private String PREFIX = "/backend/cdc/cdcsign/";

	@Autowired
	private ICdcSignService cdcSignService;
	

    /**
     * 跳转到生命体征列表首页
     */
    @RequestMapping("")
    @Permission("cdcsign:list")
    public String index() {
        return PREFIX + "cdcsign.html";
    }
	
    /**
     * 跳转到新增生命体征
     */
    @RequestMapping("/to_add")
    @Permission("cdcsign:add")
    public String toAdd() {
        return PREFIX + "cdcsign_add.html";
    }
	
	/**
     * 跳转到修改生命体征
     */
    @RequestMapping("/to_update/{cdcSignId}")
    @Permission("cdcsign:update")
    public String toUpdate(@PathVariable Long cdcSignId, Model model) {
        CdcSignEntity cdcSign = this.cdcSignService.selectById(cdcSignId);
        model.addAttribute("cdcSign",cdcSign);
        return PREFIX + "cdcsign_edit.html";
    }

    /**
     * 获取生命体征列表
     */
	@SuppressWarnings("unchecked")
    @RequestMapping(value = "/list")
    @ResponseBody
    @Permission("cdcsign:list")
    public Object list(@RequestParam Map<String, Object> params) {
		Page<CdcSignEntity> page = new PageFactory<CdcSignEntity>().defaultPage();
        List<CdcSignEntity> result = this.cdcSignService.page(page,params);
        page.setRecords((List<CdcSignEntity>) new EmptyWarpper(result).warp());
        return R.packForBT(page);
    }

    /**
     * 新增生命体征
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    @Permission("cdcsign:add")
    @BussinessLog(value = "新增生命体征")
    public Object add(CdcSignEntity cdcSign) {
        if (CommonUtil.isOneEmpty(cdcSign)) {
            throw new BizException(BizExceptionEnum.REQUEST_NULL);
        }
        cdcSign.insert();
        return R.ok();
    }

    /**
     * 删除生命体征
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    @Permission("cdcsign:delete")
    @BussinessLog(value = "删除生命体征")
    public Object delete(@RequestParam Long cdcSignId) {
	
        this.cdcSignService.deleteById(cdcSignId);

        return R.ok();
    }

    /**
     * 修改生命体征
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    @Permission("cdcsign:update")
    @BussinessLog(value = "修改生命体征")
    public Object update(CdcSignEntity cdcSign) {
        if (CommonUtil.isOneEmpty(cdcSign)) {
            throw new BizException(BizExceptionEnum.REQUEST_NULL);
        }
        CdcSignEntity old = this.cdcSignService.selectById(cdcSign.getId());

        old.setEpisodeId(cdcSign.getEpisodeId());
        old.setCode(cdcSign.getCode());
        old.setDescription(cdcSign.getDescription());
        old.setValue(cdcSign.getValue());
        old.setCheckDate(cdcSign.getCheckDate());
        old.setDataId(cdcSign.getDataId());
        old.setIsActive(cdcSign.getIsActive());
        old.updateAllColumnById();
        return R.ok();
    }
	
}
